﻿namespace iFinance.SqoDAL
{
    using System;
    using System.Windows;
    using iFinance.Infrastructure;
    using iFinance.Infrastructure.Events;
    using Microsoft.Practices.Prism.Events;
    using Microsoft.Practices.Unity;
    using Sqo;

    /// <summary>
    /// Siaqodb数据库操作帮助类，操作用户独立的数据库
    /// </summary>
    public class IndividualSqoHelper
    {
         #region 单例

        static IndividualSqoHelper()
        {
            Instance = new IndividualSqoHelper();
        }

        private IndividualSqoHelper()
        {            
        }

        public static IndividualSqoHelper Instance { get; set; }

        #endregion

        #region 属性

        /// <summary>
        /// 数据库上下文实例
        /// </summary>
        public Siaqodb DBContext { get; set; }

        #endregion

        #region 方法        

        /// <summary>
        /// 通用插入方法
        /// </summary>
        /// <param name="obj"></param>
        public bool Insert(object obj)
        {
            bool result = false;
            try
            {
                DBContext.StoreObject(obj);
                DBContext.Flush();
                result = true;
            }
            finally { }
            return result;
        }

        /// <summary>
        /// 通用删除方法
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool Delete(object obj)
        {
            bool result = false;
            try
            {
                DBContext.Delete(obj);
                DBContext.Flush();
                result = true;
            }
            finally { }
            return result;
        }

        /// <summary>
        /// 通用更新方法
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool Update(object obj)
        {
            bool result = false;
            try
            {
                DBContext.StoreObject(obj);
                DBContext.Flush();
                result = true;
            }
            finally { }
            return result;
        }

        #endregion
    }
}
